import { createRouter, createWebHistory } from "vue-router";
import Cookies from "js-cookie";
const routes = [
    {
        path: '/',
        name: 'index',
        redirect: "/PageCommunity"

    },
    {
        path: '/LoginView',
        name: 'LoginView',
        component: () => import('../views/LoginView.vue'),
    },
    {
        path: '/IndexBook',
        name: 'IndexBook',
        component: () => import('../views/IndexBook.vue'),
        children:[
            {
                path: '/PageCommunity',
                name: 'PageCommunity',
                component: () => import('../views/PageCommunity.vue'),
            },
            {
                path: '/DetailPage',
                name: 'DetailPage',
                component: () => import('../views/DetailPage.vue'),
            },
            {
                path: '/ReleasePage',
                name: 'ReleasePage',
                component: () => import('../views/ReleasePage.vue'),
            },
    
            
            {
                path: '/IndividualCenter',
                name: 'IndividualCenter',
                redirect: '/MyAttention',
                component: () => import('../views/IndividualCenter.vue'),
                children:[
                    {
                        // 帖子
                        path: '/PagePost',
                        name: 'PagePost',
                        component: () => import('../components/user/PagePost.vue'),
                    },
                    {
                        // 评论
                        path: '/MyComment',
                        name: 'MyComment',
                        component: () => import('../components/user/MyComment.vue'),
                    },
                    {
                        // 关注
                        path: '/MyAttention',
                        name: 'MyAttention',
                        component: () => import('../components/user/MyAttention.vue'),
                    },
                    {
                        // 粉丝
                        path: '/MyFans',
                        name: 'MyFans',
                        component: () => import('../components/user/MyFans.vue'),
                    },
                    {
                        // 收藏
                        path: '/MyCollection',
                        name: 'MyCollection',
                        component: () => import('../components/user/MyCollection.vue'),
                    },
                    {
                        // 编辑资料
                        path: '/EditData',
                        name: 'EditData',
                        component: () => import('../components/user/EditData.vue'),
                    },
                    {
                        // 隐私设置
                        path: '/PrivacySettings',
                        name: 'PrivacySettings',
                        component: () => import('../components/user/PrivacySettings.vue'),
                    },
                    {
                        // 反馈
                        path: '/MyFeedback',
                        name: 'MyFeedback',
                        component: () => import('../components/user/MyFeedback.vue'),
                    },
                ]
            },
        ]
    },
    // 登陆
    {
        path: '/LoadingPage',
        name: 'LoadingPage',
        component: () => import('../views/LoadingPage.vue'),
    },


    {
        path: '/InterestSurvey',
        name: 'InterestSurvey',
        component: () => import('../views/InterestSurvey.vue'),
    },
    // 根据需要添加更多路由
];
const router = createRouter({
    history: createWebHistory(),
    routes,
});

router.beforeEach((to, from, next) => {
    if (Cookies.get("token") != null) {
        next();
    } else {
        if (to.meta.isRelease) {
            //没有token isRelease为true 守卫不让进,跳入login
            next("/LoginView");
        } else {
            next();
        }
    }
});
export default router;